Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MODE_NOLOG #18

Merged
merged 15 commits into from
Sep 20, 2023
Merged

Added MODE_NOLOG #18

merged 15 commits into from
Sep 20, 2023

Conversation

4c3y
Copy link
Member

@4c3y 4c3y commented Sep 6, 2023

Added MODE_NOLOG to disable logging completely. Useful for unittests where logging can be ignored or in some cases for release builds.

  • Implemented MODE_NOLOG
  • Added Unittest suite for MODE_NOLOG
  • Fixed and refactored some MODE_LPP unittests
  • Fixed potential deadlock in async_tests.h

@4c3y 4c3y requested review from michaelpantic and rikba September 7, 2023 16:43
@4c3y 4c3y marked this pull request as ready for review September 7, 2023 16:44
@4c3y 4c3y added the enhancement New feature or request label Sep 7, 2023
Copy link
Member

@michaelpantic michaelpantic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

It seems that in NoLog you log empty strings, right? Is there a technical difference in just redirecting the calls to not doing anything at all, to logging empty strings? With empty string you'd probably still transfer \0 to the stream, not sure if that makes a difference though.

@michaelpantic michaelpantic merged commit 3dc97f4 into master Sep 20, 2023
1 check passed
@4c3y
Copy link
Member Author

4c3y commented Sep 20, 2023

It actually doesn't log empty strings (The console would spam empty lines). The emptyString() function is constexpr and generates an empty string at compile-time, which is then passed to InternalLog() using a stream operator. This is useful to check at compile-time if the logging function signatures are valid, in case the code switched to a different mode (e.g. MODE_LPP). Inside InternalLog(), the following constructor and destructor are invoked:

class InternalLog() {
public:
  InternalLog() {
    should_print_ = false;
  };

 virtual ~InternalLog() {
    if (!should_print_) {
      return; //Returns here
    }
   //print logic here
  }
}

When utilizing the LPP_CAPTURE_STDOUT() macro during unittesting, an empty string is returned if nothing is printed.

@4c3y 4c3y deleted the feature/nolog branch September 21, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants